<?php
//判断是否点击了登录
if(isset($_POST["sub"])){
	//导入数据库配置文件
	require("../conn/conn.php");
	$id = $_POST["par_id"];
	$pwd = $_POST["par_pwd"];
	
	//若用户名或密码没有输入，则返回登录页面
	if($id == ""||$pwd == ""){
		echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."用户名或密码不能为空！"."\"".")".";"."</script>";
		echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."html/家长登录页.html"."\""."</script>";
		exit;
	}
	
	//sql语句
	$sql_select = "select * from par_info where par_id = '$id' and par_pwd = '$pwd'";
	
	//获取结果
	$ret = mysqli_query($conn,$sql_select);
	$row = mysqli_fetch_array($ret); 
	
	//用户密码正确
	if($id == $row['par_id']&& $pwd == $row['par_pwd']){
		//跳转登陆成功页面
		$sql_getName = "select par_child_name from par_info where par_id = '$id'";
		$ret = mysqli_query($conn,$sql_getName);
		$row = mysqli_fetch_array($ret); 
		echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."../homepage/par_page/html/家长主页.php"."\""."</script>";
	}else{
		//跳转登陆失败页面
		echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."用户名或密码错误！"."\"".")".";"."</script>";
		echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."html/家长登录页.html"."\""."</script>";
		exit;
	}
	
	//登录后将数据写入配置文件
	$fp = fopen("../config/user_id.txt",'w');
	fwrite($fp,$id);
	fclose($fp);
	
	//关闭数据库
	mysqli_close($conn);
}